package com.forum.dao;

import com.forum.entity.Note;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface NoteDao {

    //插入一条文章
    @Insert("insert into note (user_id, title, msg,img, annex, outline,create_time, update_time, type) values (#{userId},#{title},#{msg},#{img},#{annex},#{outline},#{createTime},#{updateTime},#{type})")
    void addNote(Note note);

    //判断用户是否存在
    @Select("select count(*) from users where id = #{userId}")
    int checkIdHave(int userId);

    //根据用户id，文章类型，动态查询文章
    List<Note> findNote(@Param("id") Integer id,
                        @Param("userId") Integer userId,
                        @Param("type") Integer type,
                        @Param("noteTitle") String noteTitle,
                        @Param("updateTime") LocalDateTime updateTime);

    @Select("select count(*) from likes where note_id = #{noteId}")
    int getlike(Integer noteId);

    //更新数据
    void update(Note note);

    @Delete("delete from note where id = #{id}")
    void delNote(Integer id);

    Integer findNoteByUserId(Integer noteId);

    @Select("select count(*) from note where user_id = #{userId}")
    int getNoteNumByUserId(Integer userId);

    @Select("select id from note where user_id = #{userId}")
    int[] getNoteIdsByUserId(Integer userId);
}
